package cn.ffcs.uec.common.component;

import org.zkoss.zk.ui.Components;
import org.zkoss.zk.ui.IdSpace;
import org.zkoss.zul.Tree;

import cn.ffcs.uec.common.vo.UecBdPsncl;
import cn.ffcs.uom.common.zkplus.zul.tree.model.BaseTreeModel;
import cn.ffcs.uom.common.zkplus.zul.tree.node.impl.TreeNodeImpl;
import cn.ffcs.uom.common.zkplus.zul.tree.render.BaseTreeitemRenderer;
import lombok.Getter;
import lombok.Setter;

public class BdPsnclTree extends Tree implements IdSpace {

    private static final long serialVersionUID = -5112899192298675973L;

    @Getter
    @Setter
    private BdPsnclTreeBandboxExt bdPsnclTreeBandboxExt;

    public BdPsnclTree() {
        Components.wireVariables(this, this);
        Components.addForwards(this, this, '$');
    }

    public void onCreate() {
        this.setSclass("zt-tree-scroll");
        bindTree();
    }

    /**
     * 初始化树结构
     */
    @SuppressWarnings("deprecation")
    public void bindTree() {
        UecBdPsncl uecBdPsncl = UecBdPsncl.newInstance();
        uecBdPsncl.setIsRoot(true);
        if (bdPsnclTreeBandboxExt != null) {
            uecBdPsncl.setComponent(bdPsnclTreeBandboxExt);
        }
        final TreeNodeImpl<UecBdPsncl> treeNode = new TreeNodeImpl<UecBdPsncl>(uecBdPsncl);
        treeNode.readChildren();
        this.setModel(new BaseTreeModel(treeNode));
        if (bdPsnclTreeBandboxExt != null) {
            this.setItemRenderer(new BdPsnclTreeitemRenderer(bdPsnclTreeBandboxExt));
        } else {
            this.setTreeitemRenderer(new BaseTreeitemRenderer());
        }
    }
}
